using System;

public partial class ExcelHelp
    {
        [Excel(typeof(int))]
        public object Int值(object rowdata)
        {
            if (rowdata is DBNull)
            {
                return 0;
            }
            else
            {
                int value = 0;
                if (int.TryParse(rowdata.ToString(), out value))
                {
                    return value;
                }
                else
                {
                    BDebug.Error($"与定义的字段类型不同{rowdata.GetType()}!=int");
                    return 0;
                }
            }
        }
        
        [Excel(typeof(string))]
        public object String值(object rowdata)
        {
            if (rowdata is DBNull)
            {
                return "";
            }
            else
            {
                return rowdata.ToString();
            }
        }
        
        [Excel(typeof(float))]
        public object Float值(object rowdata)
        {
            if (rowdata is DBNull)
            {
                return 0f;
            }
            else
            {
                float value = 0;
                if (float.TryParse(rowdata.ToString(), out value))
                {
                    return value;
                }
                else
                {
                    BDebug.Error($"与定义的字段类型不同{rowdata.GetType()}!=float");
                    return 0f;
                }
            }
        }
        
        [Excel(typeof(bool))]
        public object Bool值(object rowdata)
        {
            if (rowdata is DBNull)
            {
                return false;
            }
            else
            {
                string s = rowdata.ToString().ToLower();
                if (s == "true")
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
    }

